<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use App\Model\AdminFeedback;
use App\Http\Controllers\Api\IndexApi;
use App\Http\Controllers\Home\ShowLinksController;
use App\Model\HomeUserModel;


class HomeFeedback extends Controller
{
    public function BackList()
    {
        $sate = IndexApi::getsate();

        //查询友情链接数据
        $link = new ShowLinksController;
        $linksArray = $link->index();

        //查询用户数据
        $userinfo = HomeUserModel::select('id', 'username', 'sex', 'email', 'member', 'pic')->first()->toArray();
        
        return view('Home.goods-feedback', ['sate' => $sate, 'linksArray' => $linksArray, 'userinfo' => $userinfo]);
    }

    public function BackAdd(Request $request)
    {

        //接收提交过来的数据
        $userid = session('Homeuser-data')['id'];
    	$username = session('Homeuser-data')['username'];
    	$msg = $request->input('msg');

        //判断提交内容是否为空
    	if (empty($msg)) {

    		return back()->with('message', '请先填写再提交！');
    	}

    	$type = $request->input('type');
        
        //判断选择要反馈的类型是否为空
        if (empty($type)) {

            return back()->with('message', '请选择要反馈的类型！');

        }

        //接收传过来的数据 
    	$updated = date('Y-m-d H:i:s');

        //将数据插入数据库
    	$back = DB::table('shop_user_feedbacks')->insert(['username' => $username, 'user_id' => $userid, 'msg' => $msg, 'type' => $type, 'updated_at' => $updated]);


    	 //判断是否插入成功
    	if ($back == 0) {

    		return back()->with('message', '发表失败');

    	} 

    	return back()->with('message', '发表成功');

    }
}
